package com.focus.wecenter.pojo;

import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.Type;

import javax.persistence.*;
import java.util.Date;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;

/**
 * @description
 * TODO: pojo用freemarker生成模版类
 * @author		Lv Jing
 * @date		2018-1-6 11:13:18
 */
@Entity
@Table(name = "topic", schema = "wecenter")
@DynamicInsert
@DynamicUpdate
public class Topic implements Serializable {
	private static final long serialVersionUID = 1L;

	private Integer id;
	/**话题名称*/
	private String topicName;
	/**话题关注度*/
	private Integer concernNumber;
	/**话题描述*/
	private String topicDescription;
	/**话题图片*/
	private String topicPic;
	/**讨论计数*/
	private Integer discussCount;
	/**创建时间*/
	private Date createTime;
	/**更新时间*/
	private Date updateTime;
    /**创建该话题的用户*/
    private User user;
    /**该话题下所有的问题*/
    private Set<Question> involveQuestions = new HashSet<>(0);
    /**该话题下的所有文章*/
    private Set<Article> involveArticle = new HashSet<>(0);
    /**关注用户*/
    private Set<User> focusUsers = new HashSet<>(0);

    @JoinTable(name = "topic_article", joinColumns = {@JoinColumn(name = "topic_id")}, inverseJoinColumns = {@JoinColumn(name = "article_id")})
    @ManyToMany
    @OrderBy("createTime desc")
    public Set<Article> getInvolveArticle() {
        return involveArticle;
    }
    public void setInvolveArticle(Set<Article> involveArticle) {
        this.involveArticle = involveArticle;
    }
    @JoinTable(name = "topic_focus", joinColumns = {@JoinColumn(name = "topic_id")}, inverseJoinColumns = {@JoinColumn(name = "user_id")})
	@ManyToMany
	public Set<User> getFocusUsers() {
		return focusUsers;
	}
	public void setFocusUsers(Set<User> focusUsers) {
		this.focusUsers = focusUsers;
	}
	@JoinTable(name = "topic_question", joinColumns = {@JoinColumn(name = "topic_id", referencedColumnName = "topic_id")}, inverseJoinColumns = {@JoinColumn(name = "question_id", referencedColumnName = "question_id")})
    @ManyToMany
    @OrderBy("createTime desc")
    public Set<Question> getInvolveQuestions() {
        return involveQuestions;
    }
    public void setInvolveQuestions(Set<Question> involveQuestions) {
        this.involveQuestions = involveQuestions;
    }
    @Id
    @Column(name = "TOPIC_ID")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
    @JoinColumn(name = "USER_ID")
    @ManyToOne
    public User getUser() {
        return user;
    }
    public void setUser(User user) {
        this.user = user;
    }
	@Basic
    @Column(name = "TOPIC_NAME")
	public String getTopicName() {
		return this.topicName;
	}
	public void setTopicName(String topicName) {
		this.topicName = topicName;
	}	
	@Basic
    @Column(name = "CONCERN_NUMBER")
	public Integer getConcernNumber() {
		return this.concernNumber;
	}
	public void setConcernNumber(Integer concernNumber) {
		this.concernNumber = concernNumber;
	}	
	@Basic
    @Lob
    @Type(type = "text")
    @Column(name = "TOPIC_DESCRIPTION")
	public String getTopicDescription() {
		return this.topicDescription;
	}
	public void setTopicDescription(String topicDescription) {
		this.topicDescription = topicDescription;
	}	
	@Basic
    @Column(name = "TOPIC_PIC")
	public String getTopicPic() {
		return this.topicPic;
	}
	public void setTopicPic(String topicPic) {
		this.topicPic = topicPic;
	}	
	@Basic
    @Column(name = "DISCUSS_COUNT")
	public Integer getDiscussCount() {
		return this.discussCount;
	}
	public void setDiscussCount(Integer discussCount) {
		this.discussCount = discussCount;
	}	
	@Basic
    @Column(name = "CREATE_TIME")
	public Date getCreateTime() {
		return this.createTime;
	}
	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}	
	@Basic
    @Column(name = "UPDATE_TIME")
	public Date getUpdateTime() {
		return this.updateTime;
	}
	public void setUpdateTime(Date updateTime) {
		this.updateTime = updateTime;
	}

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        Topic topic = (Topic) o;
        return Objects.equals(id, topic.id);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id);
    }
}